package com.ruoyi.web.controller.comlbs;


import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AlarmRule;
import com.ruoyi.system.service.IAlarmRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 指令配置Controller
 * 
 * @author wp
 * @date 2023-08-10
 */
@RestController
@RequestMapping("/comlbs/alarmRule")
public class AlarmRuleController extends BaseController {

    @Autowired
    private IAlarmRuleService alarmRuleService;

    @ApiOperation("指令配置列表")
    @ApiOperationSupport(includeParameters = {"ruleType","name","companyId"})
    @GetMapping("/list")
    public TableDataInfo list(AlarmRule alarmRule) {
        startPage();
        List<AlarmRule> list = alarmRuleService.selectList(alarmRule);
        return getDataTable(list);
    }

    /**
     * 获取指令配置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(alarmRuleService.getById(id));
    }

    @ApiOperation("新增指令配置")
    @ApiOperationSupport(includeParameters = {"companyId","name","pageTag","ruleAttr","ruleType","confValue"})
    @Log(title = "指令配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlarmRule alarmRule) {
        return toAjax(alarmRuleService.save(alarmRule));
    }

    @ApiOperation("编辑指令配置")
    @ApiOperationSupport(includeParameters = {"id","companyId","name","pageTag","ruleAttr","ruleType","confValue"})
    @Log(title = "指令配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlarmRule alarmRule) {
        return toAjax(alarmRuleService.updateById(alarmRule));
    }

    @ApiOperation("删除指令配置")
    @Log(title = "指令配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(alarmRuleService.removeByIds(Arrays.asList(ids)));
    }
}
